package cn.xml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

/**
 * @auth wzy
 * @date 2023/9/27 16:22
 */
public class Test3 {

    public static void main(String[] args) throws DocumentException {
        SAXReader reader = new SAXReader();

        Document doc = reader.read("resources/phone.xml");

        Element root = doc.getRootElement();
        List<Element> listBrand = root.elements("brand");

        for (Element element : listBrand) {
            System.out.println("element.attribute(\"name\") = " + element.attribute("name").getValue());

            List<Element> childrenList = element.elements();
            for (Element child : childrenList) {
                System.out.print("-------child.getName() = " + child.getName());
                System.out.println(":::::child.attribute(\"name\").getValue() = " + child.attribute("name").getValue());
            }

        }

    }
}
